//package com.zero.rpc.core.registry;
//
//import ch.qos.logback.core.net.server.Client;
//import cn.hutool.json.JSONUtil;
//import com.zero.rpc.core.config.RegistryConfig;
//import com.zero.rpc.core.model.ServiceMetaInfo;
//import io.vertx.core.net.impl.pool.Lease;
//
//import java.nio.charset.StandardCharsets;
//import java.time.Duration;
//
//public class EtcdRegistry implements Registry {
//
//    private Client client;
//
//    private KV kvClient;
//
//    /**
//     * 根节点
//     */
//    private static final String ETCD_ROOT_PATH = "/rpc/";
//
//    @Override
//    public void init(RegistryConfig registryConfig) {
//        client = Client.builder().endpoints(registryConfig.getAddress()).connectTimeout(Duration.ofMillis(registryConfig.getTimeout())).build();
//        kvClient = client.getKVClient();
//    }
//
//    @Override
//    public void register(ServiceMetaInfo serviceMetaInfo) throws Exception {
//        // 创建 Lease 和 KV 客户端
//        Lease leaseClient = client.getLeaseClient();
//
//        // 创建一个 30 秒的租约
//        long leaseId = leaseClient.grant(30).get().getID();
//
//        // 设置要存储的键值对
//        String registerKey = ETCD_ROOT_PATH + serviceMetaInfo.getServiceNodeKey();
//        ByteSequence key = ByteSequence.from(registerKey, StandardCharsets.UTF_8);
//        ByteSequence value = ByteSequence.from(JSONUtil.toJsonStr(serviceMetaInfo), StandardCharsets.UTF_8);
//
//        // 将键值对与租约关联起来，并设置过期时间
//        PutOption putOption = PutOption.builder().withLeaseId(leaseId).build();
//        kvClient.put(key, value, putOption).get();
//    }
//
//
//}
